import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# 读取本地CSV文件
file_path = "D:\\qie.csv"
df = pd.read_csv(file_path)

# 打印数据集的前5行以检查数据
print(df.head(5))

# 打印列名以检查正确的列名
print("Column names:", df.columns)

# 检查是否有 'species' 列，如果列名不是 'species'，替换为实际的列名
actual_species_column = None
for column in df.columns:
    if 'species' in column.lower():  # 检查列名中是否包含 'species'
        actual_species_column = column
        break

if actual_species_column is None:
    print("Error: No column containing 'species' found in the dataset.")
else:
    print(f"Using column '{actual_species_column}' for species data.")

    # 使用条形图可视化不同种类企鹅的数量分布
    plt.figure(figsize=(10, 6))
    sns.countplot(x=actual_species_column, data=df)
    plt.title('Distribution of Penguin Species')
    plt.xlabel('Species')
    plt.ylabel('Count')
    plt.show()

    # 使用箱型图可视化不同种类企鹅的FlipperLength、CulmenLength和CulmenDepth的分布
    plt.figure(figsize=(10, 6))
    sns.boxplot(data=df, x=actual_species_column, y='FlipperLength')
    plt.title('Boxplot of FlipperLength by Species')
    plt.xlabel('Species')
    plt.ylabel('FlipperLength (mm)')
    plt.show()